class Solution
{
public:
    int minimumRefill(vector<int> &plants, int capacityA, int capacityB)
    {
        int aPos = 0;
        int bPos = plants.size() - 1;
        int a = capacityA, b = capacityB;
        int result = 0;
        while (aPos <= bPos)
        {

            if (aPos == bPos)
            {
                if (max(a, b) < plants[aPos])
                {
                    ++result;
                }
            }
            else
            {
                if (a < plants[aPos])
                {
                    a = capacityA;
                    ++result;
                }
                if (b < plants[bPos])
                {
                    b = capacityB;
                    ++result;
                }
                a -= plants[aPos];
                b -= plants[bPos];
            }

            ++aPos;
            --bPos;
        }
        return result;
    }
};